﻿<?php 

$sql = '';
switch ($cat)
{
	case 'bb':
		$sql = "SELECT id, CONCAT_WS(' ', 'Bài báo', tenloai) as tenloai FROM loaitapchi WHERE id <> 5 ORDER BY id ASC";
		break;
	case 'dt':
		$sql = 'SELECT id, tencap FROM capthuchien ORDER BY id ASC';
		break;
	case 'sm':
		$sql = 'SELECT id, tenloai FROM loaihoithao ORDER BY id ASC';
		break;
}
$result = dbQuery($sql);
$menu_item = array();
$count = dbNumRows($result);

for ($index = 0; $index < $count; $index++) 
{
	$row = dbFetchAssoc($result);
	$id = $row['id'];
	switch ($cat) 
	{
		case 'bb':
			$ten = $row['tenloai'];
			break;
		case 'dt':
			$ten = $row['tencap'];
			break;
		case 'sm':
			$ten = $row['tenloai'];
			break;
	}
	
	$parent_id = NULL;
	
	if (is_null($parent_id))
	{
		$menu_item[$id] = array('id'=>$id, 'name'=>$ten, 'id_all'=>"$id", 'children'=>array());
	}
	else
	{
		$menu_item[$parent_id]['children'][$id] = array('id'=>$id, 'name'=>$ten);
		$menu_item[$parent_id]['id_all'] .= '_' . $id;
	}
}

//$result = array();
//$result[] = array('tenbb'=>'ten bai bao', 'tomtat_bb'=>'tom tat bai bao');
//echo $count;
//var_dump($menu_item);

?>

<ul class="children" style="display: block; visibility: hidden; ">
<?php foreach ($menu_item as $item) { ?>
<li class="cat-item cat-item-1">
	<a title="" href="javascript:viewList('<?php echo $cat; ?>', '<?php echo $item['name']?>', '<?php echo $item['id_all']?>');"><?php echo $item['name']?></a>
	<?php if (count($item['children']) > 0) { ?>
	<ul class="children" style="display: block; visibility: hidden; ">
		<?php foreach ($item['children'] as $chItem) { ?>
		<li class="cat-item cat-item-137"><a href="javascript:viewList('<?php echo $cat; ?>', '<?php echo $chItem['name']?>', '<?php echo $chItem['id']?>');" title=""><?php echo $chItem['name']?></a>
			</li>
		<?php } ?>
	</ul>
	<?php } ?>
<?php } ?>
</ul>